package com.xz.example.factory;

import com.xz.example.entity.Circle;
import com.xz.example.entity.Rectangle;
import com.xz.example.entity.Triangle;
import com.xz.example.exception.UnsupportedShapeException;

/**
 * @author 张志航     
 * @version V1.0.0
 * @projectName design_mode
 * @title     Shape   
 * @package    com.xz.example.factory  
 * @date   2019/11/25 19:54  
 * @explain
 */
public abstract class Shape {

    // 画图的方法
    public abstract void draw();

    // 擦除的方法
    public abstract void erase();


    /**
     * 获取图形实例(工厂方法)
     * @param type
     * @return
     * @throws UnsupportedShapeException
     */
    public static Shape getShape(String type) throws UnsupportedShapeException {
        if ("yuan".equalsIgnoreCase(type)) return new Circle();
        else if ("fang".equalsIgnoreCase(type)) return new Rectangle();
        else if ("sanjiao".equalsIgnoreCase(type)) return new Triangle();
        else throw new UnsupportedShapeException();
    }
}
